<template>
  <common_print_dialog ref="common_print_dialog" businessType="EXPRESS_WAYBILL" v-bind="$attrs" v-on="$listeners"
    :tableModel="models" :printUrl="printUrl" :printHandler="printHandler" :previewUrl="previewUrl"
    :previewHandler="previewHandler" :previewMergeUrl="previewMergeUrl" :previewMergeHandler="previewMergeHandler" />
</template>

<script>
import common_print_dialog from './common_print_dialog.vue'
import role_system_mixin from '@/mixin/role_system_mixin';

export default {
  mixins: [role_system_mixin,],
  components: { common_print_dialog },
  data() {
    return {
      printUrl: null,
      previewUrl: null,
      previewMergeUrl: null,
      models: [
        { key: 'trackNumber', label: 'label_order_code', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'totalVolume', label: 'label_volume', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'totalWeight', label: 'label_weight', 'min-width': 140, 'show-overflow-tooltip': true, },
        // { key: 'totalQuantity', label: 'label_package_number', 'min-width': 140, 'show-overflow-tooltip': true, },
      ]
    }
  },
  props: {

    basePrint: false,

  },
  created() {
    this.printUrl = "/tms-api/waybill/TmsExpressPrintClientRpc/printByWaybill.json"
    this.previewUrl = "/tms-api/waybill/TmsExpressPrintClientRpc/previewWaybill.json"
    // this.previewMergeUrl = "/wms-api/inbound/WmsInboundOverseasInboundOrderRpc/mergeBox.json"

  },
  methods: {


    printHandler(data, rows) {
      data.waybillIds = rows.map(row => row.id)
      data.printNum = data.printNumSum
      return data
    },
    previewHandler(data, row) {
      data.waybillId = row.id
      data.printNum = data.printNumSum
      return data
    },
    previewMergeHandler(data, rows) {

      return data
    },

    show(rows) {
      this.$ajax({
        url: "/tms-api/waybill/TmsExpressPrintClientRpc/queryWaybills.json",
        method: 'post',
        type: 'form',
        data: { trackIds: rows.map(row => row.id) },
        success: (res) => {
          if (res.data) {
            this.$refs.common_print_dialog.show(res.data.rows)
          }
        }
      })
    }
  }
}
</script>
